float DEG2RAD = 3.14159/180;

class Ball {
  float radius;
  float xpos, ypos;
  float xvel, yvel;
  float alpha;

  void init(float x, float y) {
    this.alpha = 1.0;
    this.radius = 3.0;
    this.xpos = (float)x;
    this.ypos = (float)y;
    this.xvel = (width/height)*7;
    this.yvel = (width/height)*7;
  }

  void update() {
    xpos += xvel;
    ypos += yvel;
    if(xpos > width) {
      xvel *= -1.0;
      xpos = width-1;
    }
    if(xpos < 0) {
      xvel *= -1.0;
      xpos = 1;
    }
    if(ypos > height) {
      //ballSystem.removeBall();
      //yvel *= -1.0;
      //ypos = height-1;
      //ballSystem.removeBall();
      ballSystem.curIndex--;
    }
    if(ypos < 0) {
      yvel *= -1.0;
      ypos = 1;
    }
    //Paddle Collision
    if(xpos < paddleSystem.paddles[0].xpos+40) {
      if(xpos > paddleSystem.paddles[0].xpos-40) {
        if(ypos > paddleSystem.paddles[0].ypos-5) {
          if(ypos < paddleSystem.paddles[0].ypos+5) {
            yvel *= -1.0;
          }
        }
      }
    }
    //Block Collision
    if(xpos < blockSystem.particles[0].position().x()+30) {
      if(xpos > blockSystem.particles[0].position().x()-30) {
        if(ypos > blockSystem.particles[0].position().y()-10) {
          if(ypos < blockSystem.particles[0].position().y()+10) {
            blockSystem.physics.setGravity(xvel*.01,yvel*.01,0);
            blockSystem.particles[0].makeFree();
            blockSystem.particles[1].kill();
            yvel *= -1.0;
          }
        }
      }
    }
    
  }  

  void drawOldSchool(GL gl) {
    gl.glColor3f(alpha, alpha, alpha);
    gl.glVertex2f(xpos-2,ypos-2);
    gl.glVertex2f(xpos+2,ypos-2);
    gl.glVertex2f(xpos+2,ypos+2);
    gl.glVertex2f(xpos-2,ypos+2);
  }
}

